<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="<c:url value='/static/jquery/jquery-1.9.1.min.js'/>"
	type="text/javascript"></script>
<script type="text/javascript"
	src="<c:url value='/static/themes/js/jquery.datatables.min.js'/>"></script>
<script type="text/javascript"
	src="<c:url value='/static/datetimepicker/js/bootstrap-datetimepicker.js'/>"
	charset="UTF-8"></script>
<title>买手提现管理页面</title>
</head>
<body>
	<div class="panel panel-default bk-bg-white">
		<div class="panel-body">
			<form class="form-horizontal" id="searchForm" method="post"
				action="#">
				<div class="row">
					<div class="form-group col-sm-4">
						<label class="col-sm-4 control-label">买手生财ID：</label>
						<div class="col-sm-8">
							<input type="text" class="form-control" name="buyersUserID"
								id="buyersUserID" placeholder="买手生财ID">
						</div>
					</div>
					<div class="form-group col-sm-4">
						<label class="col-sm-4 control-label">提现金额：</label>
						<div class="col-sm-8">
							<input type="text" class="form-control" name="minMoneyAmout"
								id="minMoneyAmout" placeholder="提现金额最小值">

						</div>
					</div>
					<div class="form-group col-sm-4">
						<label class="col-sm-1 control-label">-</label>
						<div class="col-sm-8">
							<input type="text" class="form-control" name="maxMoneyAmout"
								id="maxMoneyAmout" placeholder="提现金额最大值">
						</div>
					</div>
				</div>
				<div class="row">
					<div class="form-group col-sm-4">
						<label class="col-sm-4 control-label">提现状态：</label>
						<div class="col-sm-8">
							<select id="statusInfor" name="statusInfor" class="form-control">
								<option value="">全部状态</option>
								<option selected="selected" value="1">待处理</option>
								<option value="2">已提现</option>
							</select>
						</div>
					</div>
					<div class="form-group col-sm-4">
						<label class="col-sm-4 control-label">申请时间：</label>
						<div class="col-sm-8">
							<input class="input-append date form_datetime form-control"
								name="startRaiseCashTime" id="startRaiseCashTime"> <span
								class="add-on"><i class="icon-remove"></i></span> <span
								class="add-on"><i class="icon-calendar"></i></span>
						</div>
					</div>
					<div class="form-group col-sm-4">
						<label class="col-sm-1 control-label">-</label>
						<div class="col-sm-8">
							<input class="input-append date form_datetime form-control"
								name="endRaiseCashTime" id="endRaiseCashTime"> <span
								class="add-on"><i class="icon-remove"></i></span> <span
								class="add-on"><i class="icon-calendar"></i></span>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="form-group col-sm-4">
						<label class="col-sm-4 control-label">提现银行：</label>
						<div class="col-sm-8">
							<input type="text" class="form-control" name="bankName"
								id="bankName" placeholder="提现银行">
						</div>
					</div>
					<div class="form-group col-sm-4">
						<label class="col-sm-4 control-label">开户城市：</label>
						<div class="col-sm-8">
							<input type="text" class="form-control" name="areaName"
								id="areaName" placeholder="开户城市">
						</div>
					</div>
				</div>
				<div class="form-group col-sm-12"
					style="padding-bottom: 15px; text-align: center;">
					<button id="search" type="button"
						class="btn btn-primary glyphicon glyphicon-search">搜索</button>
					<button id="report" type="button"
						class="btn btn-success glyphicon glyphicon-download">
						批量导出</button>
				</div>
			</form>
		</div>
	</div>
	<!-- panel-body -->
	<div id="message"></div>
	<!-- panel -->
	<div class="panel panel-default">
		<div class="panel-body">
			<div class="table-responsive">
				<div id="table1_wrapper" class="dataTables_wrapper no-footer">
					<div>
						<button id="sure" type="button" class="btn btn-warning">
							完成提现</button>
					</div>
					<table id="table" class="display nowrap" cellspacing="0"
						width="100%">
						<thead>
							<tr role="row">
								<th><input type="checkbox" class="checkall" />全选</th>
								<th>生财ID</th>
								<th>申请时间</th>
								<th>提现金额</th>
								<th>提现银行</th>
								<th>开户名</th>
								<th>开户城市</th>
								<th>开户行</th>
								<th>账号</th>
								<th>提现状态</th>
								<th>处理时间</th>
								<th>操作</th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
		</div>
		<div id="page"></div>
	</div>

	<script type="text/javascript">
		$(function($) {
			//日期控件
			$('#startRaiseCashTime').datetimepicker({
				language : 'zh-CN',
				format : 'yyyy-mm-dd hh:ii',
				autoclose : true,
				todayBtn : true,
				minuteStep : 10
			}).on('changeDate', function(ev) {
				var starttime = $(this).val();
				$('#endRaiseCashTime').datetimepicker('setStartDate', starttime);
				$(this).datetimepicker('hide');
			});

			$('#endRaiseCashTime').datetimepicker({
				language : 'zh-CN',
				format : 'yyyy-mm-dd hh:ii',
				autoclose : true,
				todayBtn : true,
				minuteStep : 10
			}).on('changeDate', function(ev) {
				var time = $(this).val();
				$('#startRaiseCashTime').datetimepicker('setEndDate', time);
				$(this).datetimepicker('hide');
			});

			function doSearch(refresh) {
				var table = $('#table')
						.DataTable(
								{
									"processing" : true,
									"serverSide" : true,
									"bLengthChange" : false,
									"bFilter" : false,
									"bSort" : false,
									"bDestroy" : true,
									"sScrollX" : "100%",
									"sScrollY" : "100%",
									"language" : {
										"url" : path
												+ "/static/language_datatables.json"
									},
									"ajax" : {
										"url" : path
												+ "/capital/getRaiseCashList",
										"type" : "POST",
										"async" : false,
										"data" : {
											"buyersUserID" : $('#buyersUserID')
													.val(),
											"statusInfor" : $('#statusInfor')
													.val(),
											"minMoneyAmout" : $(
													'#minMoneyAmout').val(),
											"maxMoneyAmout" : $(
													'#maxMoneyAmout').val(),
											"startRaiseCashTime" : $(
													'#startRaiseCashTime')
													.val(),
											"endRaiseCashTime" : $(
													'#endRaiseCashTime').val(),
											"bankName" : $('#bankName').val(),
											"areaName" : $('#areaName').val()
										}
									},
									"oSearch" : {

									},
									"columns" : [ {
										"data" : "buyersuserid",
										"width" : "5%"
									}, {
										"data" : "buyersuserid",
										"width" : "10%"
									}, {
										"data" : "raisecashtime",
										"width" : "10%"
									}, {
										"data" : "moneyamout",
										"width" : "10%"
									}, {
										"data" : "bankname",
										"width" : "10%"
									}, {
										"data" : "cardholdername",
										"width" : "10%"
									}, {
										"data" : "areaname",
										"width" : "10%"
									}, {
										"data" : "accountbankname",
										"width" : "10%"
									}, {
										"data" : "bankcardaccount",
										"width" : "10%"
									}, {
										"data" : "statusinfor",
										"width" : "10%"
									}, {
										"data" : "completiontime",
										"width" : "10%"
									}, {
										"data" : "buyersuserid",
										"width" : "10%"
									} ],
									"columnDefs" : [
											{
												"render" : function(data, type,
														row) {
													if (row.statusinfor == 1) {
														return '<input type="checkbox"  class="checkchild"  value="' + data + '_'+row.raisecashtime+'"/>';
													}
													return "";
												},
												"targets" : 0
											},
											{
												"render" : function(data, type,
														row) {
													return dateTimeFormatter(data);
												},
												"targets" : 2
											},
											{
												"render" : function(data, type,
														row) {
													return dateTimeFormatter(data);
												},
												"targets" : 10
											},
											{
												"render" : function(data, type,
														row) {
													if (data == "1") {
														return "待处理";
													} else if (data == "2") {
														return "已提现";
													} else {
														return "";
													}
												},
												"targets" : 9
											},
											{
												"render" : function(data, type,
														row) {
													if (row.statusinfor == 1) {
														var ret = '<button class="btn btn-warning recharge" key="'+data+'" statusInfor="2" time="'+row.raisecashtime+' ">完成提现</button>&nbsp;'
														return ret;
													}
													return "";
												},
												"targets" : 11
											}, ]

								});
			}
			;
			doSearch();
			//查询事件
			$('#search').click(function() {
				doSearch();
			});

			bandclick();
			bindCheck();
			$(".checkall").click(function() {
				var check = $(this).prop("checked");
				$(".checkchild").prop("checked", check);
			});
			function bindCheck() {
				$("body").on("click", ".checkchild", function() {
					var child = $(".checkchild");
					var ifCheckAll = true;
					for (var i = 0; i < child.length; i++) {
						var check = $(child[i]).prop("checked");
						if (!check) {
							ifCheckAll = false;
							$(".checkall").prop("checked", "false");
							break;
						}
					}
					$(".checkall").prop("checked", ifCheckAll);
				});

			}
			;

			function bandclick() {
				$('body').on("click", '.recharge', function() {
					_t = $(this);
					var buyersUserID = _t.attr('key');
					var raiseCashTime = _t.attr('time');
					var statusInfor = _t.attr('statusInfor');
					updateStatus(buyersUserID, raiseCashTime, statusInfor);
				});
			}
			$("#sure").on("click", function() {
				var child = $(".checkchild:checked");
				if (child.length == 0) {
					alert("请选择需要操作的信息");
					return false;
				}
				var buyersUserID = "";
				var raiseCashTime = "";
				child.each(function(i, o) {
					var value = o.value.toString().split("_");
					buyersUserID += value[0];
					raiseCashTime += value[1];
					if (i != child.length - 1) {
						raiseCashTime += ",";
						buyersUserID += ",";
					}
				});
				updateStatus(buyersUserID, raiseCashTime, "2");

			});

			function updateStatus(buyersUserID, raiseCashTime, statusInfor) {
				$.blockUI({ message: '加载中...' });
				$.ajax({
					type : "post",
					url : path + "/capital/updateRaiseCash",
					cache : false,
					data : {
						buyersUserID : buyersUserID,
						raiseCashTime : raiseCashTime,
						statusInfor : statusInfor,
						_t : new Date().getTime()
					},
					dataType : "json",
					success : function(data) {
						showmessage(data.msg);
						if (data.success) {
							doSearch();
						}else{
							$.unblockUI();
						}
					}
				});
			}

		});

		//导出
		$('#report').click(function() {
			$('#searchForm').attr("action", path + "/capital/reportRaiseCash");
			$('#searchForm').submit();
			$('#searchForm').attr("action", "");
		});

		//显示消息
		function showmessage(msg, callback) {
			$('#message').ucMessage({
				msg : msg,
				callback : callback
			});
		}
	</script>
</body>
</html>